﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteAlways]
public class Cell : MonoBehaviour
{
    [Range(-20, 20)]
    public float cellValue;
    private static MaterialPropertyBlock materialPropertyBlock;
    private void OnEnable() {
        OnValidate();
    }

    private void OnValidate() {
        if(materialPropertyBlock == null) materialPropertyBlock = new MaterialPropertyBlock();
        float value = 0;
        if(cellValue < 0) value = -Mathf.Pow(2, -cellValue);
        else if(cellValue > 0) value = Mathf.Pow(2, cellValue);
        materialPropertyBlock.SetFloat("_CellValue", value);
        this.GetComponent<Renderer>().SetPropertyBlock(materialPropertyBlock);
    }

    
    
}
